﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Common.Code
{
    [AttributeUsage(
        AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
    public class CodeAttribute : Attribute
    {
        private List<string> _descriptions;

        public VisibleLevel VisibleLevel { get; set; }

        public List<string> DescLines
        {
            get => _descriptions ?? (_descriptions = new List<string>());
            set => _descriptions = value;
        }

        public string Description
        {
            get
            {
                if (DescLines == null || DescLines.Count <= 0)
                    return string.Empty;
                return string.Join(Environment.NewLine, DescLines);
            }
        }

        public string DisplayName { get; set; }

        /// <summary>
        /// 所属模组名称
        /// </summary>
        public string GroupName { get; set; }

        public ScriptType ScriptType { get; set; }

        public CodeAttribute()
        {
            VisibleLevel = VisibleLevel.Visible;
        }

        public CodeAttribute(string description)
        {
            VisibleLevel = VisibleLevel.Visible;
            DescLines.Add(description);
        }

        public CodeAttribute(VisibleLevel visibleLevel, params string[] descriptionLines)
        {
            VisibleLevel = visibleLevel;
            DescLines.AddRange(descriptionLines);
        }
    }

    public enum VisibleLevel
    {
        Visible,
        Hide,
        Debug,
        ReadOnly,
        WriteOnly
    }

    /// <summary>
    /// 脚本类型
    /// </summary>
    public enum ScriptType
    {
        /// <summary>
        /// 对象
        /// </summary>
        Object,

        /// <summary>
        /// 命令
        /// </summary>
        Command,
    }
}